
export default {
  name: 'LoginRegister',
  data() {
    return {
      currentForm: 'login', // 初始化 currentForm
      login: {
        phone: '',
        password: '',
        identity: 'patient',
        agreed: false
      },
      register: {
        phone: '',
        code: '',
        password: '',
        identity: 'patient',
        nickname: '',
        avatar: null,
        gender: 'male',
        age: '',
        region: '',
        condition: ''
      },
      forgot: {
        phone: '',
        code: '',
        newPassword: '',
        confirmPassword: ''
      },
      showAgreementWarning: false,
      passwordMismatch: false
    };
  },
  methods: {
    switchForm(form) {
      this.currentForm = form;
      this.showAgreementWarning = false;
      this.passwordMismatch = false;
    },
    handleLogin() {
      if (!this.login.agreed) {
        this.showAgreementWarning = true;
        return;
      }
      alert('登录成功（模拟）');
      localStorage.setItem('isLoggedIn', 'true'); // 保存登录状态
      this.$router.push('/Index'); // 跳转到首页
    },
    handleRegister() {
      alert('注册成功（模拟）');
      localStorage.setItem('isLoggedIn', 'true'); // 保存登录状态
      this.$router.push('/Index'); // 跳转到首页
    },
    handleForgotPassword(e) {
      if (this.forgot.newPassword !== this.forgot.confirmPassword) {
        e.preventDefault();
        this.passwordMismatch = true;
        setTimeout(() => {
          this.passwordMismatch = false;
        }, 500);
      } else {
        alert('密码重置成功（模拟）');
      }
    },
    sendCode() {
      alert('验证码已发送（模拟）');
    },
    sendForgotCode() {
      alert('验证码已发送（模拟）');
    },
    handleAvatarUpload(event) {
      this.register.avatar = event.target.files[0];
    },
    loginWithWeChat() {
      alert('跳转至微信登录（模拟）');
    },
    loginWithQQ() {
      alert('跳转至QQ登录（模拟）');
    },
    loginWithEmail() {
      alert('跳转至邮箱登录（模拟）');
    },
    loginWithCode() {
      alert('跳转至手机验证码登录（模拟）');
    }
  }
};